package com.goldplusgold.tradedelay.app.base.widget;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.goldplusgold.tradedelay.app.R;
import com.goldplusgold.tradedelay.app.my.account.Accountmanager;

/**
 * Created by Administrator on 2017/7/21.
 */

public class QuitDialog extends Dialog {
    private TextView cancle;
    private TextView confirm;
    private TextView mQuitMessageTv ;
    public QuitDialog(@NonNull Context context) {
        super(context);
        initView(context);
    }

    public QuitDialog(@NonNull Context context, @StyleRes int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    protected QuitDialog(@NonNull Context context, boolean cancelable, @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initView(context);
    }

    private void initView(Context context){
        setContentView(R.layout.quit_dialog);

        WindowManager.LayoutParams params = this.getWindow().getAttributes();
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        int displayWidth = dm.widthPixels;
        int displayHeight = dm.heightPixels;
        params.width = (int) (displayWidth * 0.8);
        //params.height = (int) (displayHeight * 0.36);
        this.getWindow().setAttributes(params);
        View rootview = this.getWindow().getDecorView();
        rootview.setBackgroundResource(R.drawable.shape_round_window);
        mQuitMessageTv = (TextView) findViewById(R.id.quit_message_tv);
        cancle = (TextView)findViewById(R.id.cancle_action);
        confirm = (TextView)findViewById(R.id.confirm_action);
        cancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        confirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
                Accountmanager.startLogin();
            }
        });
    }

    public void setMessage(String message){
        mQuitMessageTv.setText(message);
    }

}
